<?php

namespace App\Sdks\Feishu\Traits;

trait Post
{
    /**
     * @param $open_id
     * @param $title
     * @param $content
     * @return mixed
     * 发送富文本到 open_id
     */
    public function sendPostToOpenId($open_id, $title, $content){
        return $this->sendPost('open_id', $open_id, $title, $content);
    }

    /**
     * @param $chat_id
     * @param $title
     * @param $content
     * @return mixed
     * 发送富文本到 chat_jd
     */
    public function sendPostToChatId($chat_id, $title, $content){
        return $this->sendPost('chat_id', $chat_id, $title, $content);
    }

    /**
     * @param $target
     * @param $targetId
     * @param $title
     * @param $content
     * @return mixed
     * 发送富文本
     */
    public function sendPost($target, $targetId, $title, $content){
        $url = $this->getApiUrl('message_send');

        $param = [
            $target => $targetId,
            "msg_type" => 'post',
            "content" => [
                'post' => [
                    'zh_cn' => [
                        'title' => $title,
                        'content' => $content,
                    ]
                ],
            ],
        ];

        $ret = $this->authRequest($url, $param, 'POST');

        return $ret;
    }
}
